i`m doing my thesis comparing CORDIC with polynomial in counting arctan with fixed point. I`m using Q15 format now. I`m using this site CORDIC arctan as a referenced when making with floating point. The problem there`s a lot of error when i try to make it with fixed point.
this is my program
anyone can help?
if you have suggestion about making it with others rather than Q15 format, as long it is fixed point, it is very usefull to
this is my program
Code:
#include "Unit1.h" #include "math.h" #include "fixed_math.hpp" #define MAXBITS 15 static float invGain1; static float atanTable[MAXBITS]; static float gain1Cordic(); void initCordic() { /* must call this first to initialise the constants. * of course, here i use the maths library, but the * values would be precomputed. */ float t = 1.0f; int i; for (i = 0; i < MAXBITS; ++i) { atanTable[i] = atan(t); t /= 2; } /* set constants */ invGain1 = 1/gain1Cordic(); } /* CORDIC m=1, y-->0 */ Q15 cordic(Q15 &x0, Q15 &y0, Q15 &z0, Q15 vecmode) { short t; Q15 x, y, z; int i; t = 1.0f; x = x0; y = y0; z = z0; for (i = 0; i < MAXBITS; ++i) { double x1; if (vecmode >= 0.0f && y < vecmode || vecmode<0.0f && z >= 0.0f) { Q15 x1 = x - y>>t; y = y + x>>t; z = z - atanTable[i]; } else { Q15 x1 = x + y>>t; y = y - x>>t; z = z + atanTable[i]; } x = x1; t /= 2; } x0 = x; y0 = y; z0 = z; } static float gain1Cordic() { /* compute gain by evaluating cos(0) without inv gain */ float x, y, z; x = 1; y = 0; z = 0; cordic(&x, &y, &z, 1.0f); return x; } Q15 atanCordic(Q15 a) { /* domain: all a */ Q15 x = 1.0f; Q15 z = 0.0f; cordic(&x, &a, &z, 0.0f); return z; } void __fastcall TForm1::Button1Click(TObject *Sender) { AnsiString buf; float x; float v,c; initCordic(); for (x=0.0;x<=1.0;x=x+0.1) { Q15 y = atanCordic(x); v = atan(x); Memo1->Lines->Add(buf.sprintf("%5.2f\n", x)); Memo2->Lines->Add(buf.sprintf("%10.6f\n",Q15ToShort(v)/32768.0)); Memo3->Lines->Add(buf.sprintf("%10.6f\n",Q15ToShort(y)/32768.0)); } }
if you have suggestion about making it with others rather than Q15 format, as long it is fixed point, it is very usefull to
Comment